package golang

import (
	"sync"
	"time"

	"gitee.com/allowall-package/goutil/fn"
)

type Singleton struct {
	cTime string
}

var s *Singleton
var once sync.Once

// 双重检查 加锁保证高并发线程安全
func GetSingleton() *Singleton {
	once.Do(func() {
		s = &Singleton{cTime: time.Now().String()}
	})

	return s
}

// ---------------分割线---------------

// 测试方法
func SingletonTest() {
	fn.Dump(fn.FuncInfo())
	fn.Dump(GetSingleton())
	fn.Dump(GetSingleton())
	fn.Dump(GetSingleton())
}
